package org.idea.qiyu.live.framework.redis.starter.key;

import org.idea.qiyu.live.framework.redis.starter.key.common.RedisKeyBuilder;
import org.idea.qiyu.live.framework.redis.starter.key.common.RedisKeyLoadMatch;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: sfx
 * Date: 2023-10-01
 * Time: 19:26
 */
@Configuration
@Conditional(RedisKeyLoadMatch.class)
public class LivingRoomProviderCacheKeyBuilder extends RedisKeyBuilder {

    private static final String LIVING_ROOM_LIST_CACHE_KEY = "living_room_list";
    private static final String LIVING_ROOM_OBJ_CACHE_KEY = "living_room_obj";
    private static final String LIVING_ROOM_LOCK_CACHE_KEY = "living_room_Lock";
    private static final String LIVING_ROOM_ONLINE_SET_CACHE_KEY = "living_room_online_set";
    private static final String LIVING_ROOM_ONLINE_PK_CACHE_KEY = "living_room_online_pk";


    /**
     * 直播间列表lock的key
     *
     * @return 返回构建好的key
     */
    public String buildLivingRoomLock() {
        return super.getPrefix() + LIVING_ROOM_LOCK_CACHE_KEY;
    }

    /**
     * 直播间列表的key
     *
     * @param roomId 直播间类型
     * @return 返回构建好的key
     */
    public String buildLivingRoomObj(Integer roomId) {
        return super.getPrefix() + LIVING_ROOM_OBJ_CACHE_KEY + super.getSplitItem() + roomId;
    }

    /**
     * 直播间列表的key
     *
     * @param type 直播间类型
     * @return 返回构建好的key
     */
    public String buildLivingRoomList(Integer type) {
        return super.getPrefix() + LIVING_ROOM_LIST_CACHE_KEY + super.getSplitItem() + type;
    }

    /**
     * 代表当前直播间有哪些在线用户
     *
     * @param appId  产品id
     * @param roomId 直播间id
     * @return 构建key
     */
    public String buildLivingRoomOnlineSet(Integer appId, Integer roomId) {
        return super.getPrefix() + LIVING_ROOM_ONLINE_SET_CACHE_KEY + super.getSplitItem() + appId
                + super.getSplitItem() + roomId;
    }

    public String buildLivingOnlinePkCacheKey(Integer roomId) {
        return super.getPrefix() + LIVING_ROOM_ONLINE_PK_CACHE_KEY + super.getSplitItem() + roomId;
    }
}